#include <stdio.h>
#include <math.h>

int valid(int a, int b, int c) {
	if((a + b <= c) || (a + c <= b) || (c + b <= a))
		return 0;
	return 1;
}

double trfield(int a, int b, int c) {
	double p, P;
	p = 0.5 * (a  + b + c);
	P = sqrt(p * (p - a) * (p - b) * (p - c));
	return P;
}

int _round(double x) {
	return (int)(x + 0.5);
}

int main() {
	int t, n, a, b, c;
	float k;
	double res;

	scanf("%d", &t);
	
	while(t--) {
		res = 0.0;
		scanf("%d %f", &n, &k);
		while(n--) {
			scanf("%d %d %d", &a, &b, &c);
			if(valid(a, b, c) > 0)
				res += trfield(a, b, c);
//			printf("r=%f\n", trfield(a, b, c));
		}
//		printf("res=%d\n", _round(res / 10.0));
		printf("%d\n", (int)round(k * res / 10.0));
	}
	return 0;
}
